package com.moons.uvcdemo.eth;

import java.util.Locale;

import android.content.Context;
import android.util.Log;

public abstract class TEthernetBase {
	private   final String TAG = "TEthernetBase";
	protected final String MAC_NULL = "00:00:00:00:00:00";
	protected final int MAC_LENGTH = 17; // mac地址 "00:00:00:00:00:00" 长度为17
	protected Context mContext = null;

	protected TEthernetBase(Context context) {
		mContext = context;
	}

	// 获取mac地址
	public abstract String getMac();

	// 获取IP地址
	public abstract String getIpAddress(String interfaceName);

	// 获取子网掩码
	public abstract String getNetMask(String interfaceName);

	// 获取网关
	public abstract String getGateWay();

	// 获取DNS1
	public abstract String getDns1(Context context);

	//使用给定的 replacement 替换此字符串所有匹配给定的正则表达式的子字符串。 
	protected boolean checkMacPrefix(final String mac, final String prefix) {
		//去掉:-符号,字符串转换为大写
		final String tmpMac = mac.replaceAll("[:-]", "").toUpperCase(Locale.ENGLISH); 
		final String tmpPrefix = prefix.replaceAll("[:-]", "").toUpperCase(Locale.ENGLISH);
		Log.i(TAG, "check mac:"+tmpMac+" "+tmpPrefix);
		return tmpMac.startsWith(tmpPrefix); //判断地址段是否以ffffff开头
	}

}